package com.sooncode.project.focusservice.controller;

import com.alibaba.fastjson.JSON;
import com.sooncode.project.core.finder.Page;
import com.sooncode.project.focusservice._.base.Utils;
import com.sooncode.project.focusservice.model.CourseSetting;
import com.sooncode.project.focusservice.model.CourseSettingItem;
import com.sooncode.project.focusservice.service.CourseSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("courseSetting")
public class CourseSettingController {
    @Autowired
    private CourseSettingService service;
    @PostMapping("courseSetting")
    public boolean add(@RequestParam Map map){
        map.put("items", JSON.parseArray(map.get("items").toString(), CourseSettingItem.class));
        return service.add(map);
    }
    @PostMapping("copySetting")
    public boolean copy(@RequestParam String id){
        return service.copy(id);
    }

    @PutMapping("courseSetting")
    public boolean modify(@RequestParam String id,@RequestParam Map map){
        map.put("items", JSON.parseArray(map.get("items").toString(),CourseSettingItem.class));
        return service.modify(id,map);
    }

    @DeleteMapping("courseSetting")
    public boolean delete(@RequestParam String[] ids){
        for(String id:ids){
            service.delete(id);
        }
        return true;
    }

    @GetMapping("courseSettings")
    public Page<CourseSetting> getPageList(@RequestParam int pageSize, @RequestParam int pageIndex, @RequestParam Map map){
        map.remove("pageSize");
        map.remove("pageIndex");
        Utils.mapValueTrim(map);
        return service.getPageList(pageSize,pageIndex-1,map);
    }
    @GetMapping("publicApi/courseByLevel")
    public List<CourseSetting> getCourseByLevel(@RequestParam String age, @RequestParam double level){
        return service.getCourseByLevel(age,level);
    }
    @PutMapping("asyncItemName")
    public boolean asyncItemName(){
        return service.asyncItemName("");
    }

}
